/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package AdminCenterMain;

import AnalysistImpl.HumidityAnalysist;
import AnalysistImpl.ManagerAnalysist;
import AnalysistImpl.PressureAnalysist;
import AnalysistImpl.TemperatureAnalysist;
import AnalysistImpl.WindAnalysist;
import CommonValue.CityName;
import CommonValue.SystemTimer;
import CommonValue.Temperature;
import DTO.DrawDTO;
import DTO.PacketDTO;
import java.util.Date;
import java.util.HashMap;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Administrator
 */
public class DrawThread implements Runnable {

    protected PacketDTO _hourlyReport;

    public DrawThread(PacketDTO _hourlyReport) {
        this._hourlyReport = _hourlyReport;
    }

    @Override
    public void run() {
        ManagerAnalysist ma = new ManagerAnalysist();
        ma.installNewAnalysist(new TemperatureAnalysist());
        ma.installNewAnalysist(new HumidityAnalysist());
        ma.installNewAnalysist(new WindAnalysist());
        ma.installNewAnalysist(new PressureAnalysist());
        boolean finish = false;
        PacketDTO temp = new PacketDTO("Drawing");
        do {
            try {
                Thread.sleep(SystemTimer.CheckReportSleep);
            } catch (InterruptedException ex) {
                Logger.getLogger(DrawThread.class.getName()).log(Level.SEVERE, null, ex);
            }

            synchronized (_hourlyReport) {
                temp.clearBuffer();
                temp.addAllToBuffer(_hourlyReport.getBuffer());
            }

            if (temp != null) {
                DrawDTO result1 = ma.analysisReport(Temperature.SIGN, CityName.HANOI, temp);
                HashMap<Date, Float> du_lieu_de_ve = result1.data.get(Temperature.TEMPERATURE);
                if (du_lieu_de_ve.size() == 0) {
                    System.out.println("KHONG CO DU LIEU DE VE");
                } else {
                    System.out.println("VE TAI DAY NHE ! DUNG du_lieu_de_ve sau day :");
                    ////////////////////// Xoa sau khi code xong, kiem tra du lieu de ve
                    for (Date d : du_lieu_de_ve.keySet()) {
                        System.out.println("date : " + d + " du lieu : " + du_lieu_de_ve.get(d));
                    }
                    //////////////////////
                }


            }

        } while (!finish);
    }
}
